﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace WebApiDome.Areas.HelpPage.Controllers
{
    public class TestController : ApiController
    {
        [HttpPost]
        public async Task<IHttpActionResult> UpdateLoad()
        {
            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);
            foreach (HttpContent content in provider.Contents)
            {
                if (content.Headers.ContentDisposition.FileName != null)
                {
                    // 获取到流
                    var ms = content.ReadAsStreamAsync().Result;
                    //进行流操作  
                    using (var br = new BinaryReader(ms))
                    {
                        if (ms.Length <= 0)
                            break;
                        //读取文件内容到内存中  
                        var data = br.ReadBytes((int)ms.Length);
                        //Create  
                        //当前时间作为ID  

                        //Info  
                        FileInfo info = new FileInfo(content.Headers.ContentDisposition.FileName.Replace("\"", ""));
                    }

                }
                else
                {
                    var ms = content.ReadAsStreamAsync().Result;
                    return Ok(new StreamReader(ms, Encoding.UTF8).ReadToEnd());
                }
            }
            return Ok("上传成功");
        }
    }
}
